using System;
using System.Collections.Generic;

namespace FireStarter.CodeGeneration
{
    /// <summary>
    /// This class implement the mapping between a Tag in a template and the 
    /// contents that it will be replaced by.
    /// Each tag could be replaced by either a value string or another
    ///   replacement object that represents a template that may have its own Tags.
    /// </summary>
    public class TagReplacement
    {
        private readonly string _tag;
        private readonly IReplacement _replacement;
        public TagReplacement(string tag, IReplacement replacement)
        {
            if (tag == null) throw new ArgumentNullException("tag");
            if (replacement == null) throw new ArgumentNullException("replacement");
            _tag = tag;
            _replacement = replacement;
        }

        public string Tag
        {
            get { return _tag; }
        }

        public IReplacement Replacement
        {
            get { return _replacement; }
        }

    }

    public interface IReplacement
    {
        string ReplacementString { get; }
        string Tag { get; }
    }

    public class ValueReplacement_old:IReplacement
    {
        private readonly string _tag;
        private string _propName;

        public ValueReplacement_old(string tag)
        {
            _tag = tag;
        }

        public string ReplacementString { get; set; }

        public string Tag
        {
            get { return _tag; }
        }

        public string PropName
        {
            get { return _propName; }
            internal set { _propName = value; }//TODO: the set is for testing and should be removed later
        }
    }

    public class ForEachReplacement : IReplacement
    {
        //private readonly IList<IModelClass> _modelElementsCollection;
        //private readonly string _collectionName;
//        private readonly IList<TagReplacement> _tagReplacements = new List<TagReplacement>(10);
        private IReplacement _replacement;
        private string _tag;

        public ForEachReplacement(string tag, IReplacement replacement)//TODO: Don't pass in the replacement for this//?? maybe maybe not brett
            
        {
            _tag = tag;
            _replacement = replacement;
        }

        //public ForEachReplacement(string collectionName, IList<IModelClass> collection)
        //{
        //    _modelElementsCollection = collection;
        //    _collectionName = collectionName;
        //}

        //public IList<IModelClass> ModelElementsCollection
        //{
        //    get { return _modelElementsCollection; }
        //}
        public string ReplacementString
        {
            get { return "some content"; }//TODO:
        }

        public string Tag
        {
            get { return _tag; }
        }

        //public string CollectionName
        //{
        //    get { return _collectionName; }
        //}

//        public IList<TagReplacement> TagReplacements
//        {
//            get { return _tagReplacements; }
//        }

        public IReplacement Replacement
        {
            get { return _replacement; }
            set { _replacement = value; }//TODO: the set is for testing and should be removed later
        }
    }

    public class SimpleReplacement : IReplacement
    {
        private string _tag;
        private Dictionary<string, IReplacement> _replacements = new Dictionary<string, IReplacement>();

        public SimpleReplacement(string tag)
        {
            _tag = tag;
        }

        public string ReplacementString
        {
            get { throw new System.NotImplementedException(); }
        }

        public string Tag
        {
            get { return _tag; }
        }

        public Dictionary<string, IReplacement> Replacements
        {
            get { return _replacements; }
        }
    }

    public class FileReplacement : IReplacement
    {
        private readonly string _fileName;
        private readonly Dictionary<string, IReplacement> _replacements = new Dictionary<string, IReplacement>();

        public FileReplacement(string filename)
        {
            _fileName = filename;
        }

        public string ReplacementString
        {
            get { throw new System.NotImplementedException(); }
        }

        public string Tag
        {
            get { throw new System.NotImplementedException(); }
        }

        public string FileName
        {
            get { return _fileName; }
        }

        public Dictionary<string, IReplacement> Replacements
        {
            get { return _replacements; }
        }
    }

    public class TemplateReplacement:IReplacement
    {
        private readonly string _replacementString;

        public TemplateReplacement(string templateName)
        {
            _replacementString = templateName;
        }

        public string ReplacementString
        {
            get { return _replacementString; }
        }

        public string Tag
        {
            get { throw new System.NotImplementedException(); }
        }
    }
}